﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace OptiGear1
{
    public class Utils
    {
        public const string wowheadprefix = "http://www.wowhead.com/?item=";
        public const int META = 0;
        public const int FEET = 17;
        public const int HEAD = 6;
        public const int CHEST = 21;
        public const int HANDS = 18;
        public const int NECK = 9;
        public const int SHOULDER = 13;
        public const int BACK = 10;
        public const int WRIST = 8;
        public const int WAIST = 19;
        public const int LEGS = 3;
        public const int RING1 = 15;
        public const int RING2 = 16;
        public const int OFFHAND = 12;
        public const int RANGED = 7;
        public const int WEAPON = 11;
        public const int TWOHANDED = 14;
        public const int WEAPONENCHANT = 20;
        public const int HANDSENCHANT = 4;
        public const int FEETENCHANT = 5;
        public const int TRINKET1 = 1;
        public const int TRINKET2 = 2;

        public static string[] bodyparts = new string[] { "Meta", "Trinket", "Trinket", "Legs", "Hands Enchant", "Feet Enchant", "Head", "Ranged", "Wrist", "Neck", "Back", "Main Hand", "Held In Off-hand", "Shoulder", "Two-Hand", "Finger", "Finger", "Feet", "Hands", "Waist", "Weapon Enchant", "Chest" };

        public static string GetHtml(string url)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            // Set some reasonable limits on resources used by this request
            request.MaximumAutomaticRedirections = 4;
            request.MaximumResponseHeadersLength = 4;
            // Set credentials to use for this request.
            request.Credentials = CredentialCache.DefaultCredentials;
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            // Get the stream associated with the response.
            Stream receiveStream = response.GetResponseStream();

            // Pipes the stream to a higher level stream reader with the required encoding format. 
            StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);

            string result = readStream.ReadToEnd();
            response.Close();
            readStream.Close();
            return result;
        }

        public static void LogText(string logmsg)
        {
            //disabled

            TextWriter tw = new StreamWriter("../../log.txt", true);

            // write a line of text to the file
            tw.WriteLine(DateTime.Now + ": " + logmsg);

            // close the stream
            tw.Close();
            //*/
        }
    }
}
